package com.helloniu.wb.containers {

import com.helloniu.fl.util.*;
import com.helloniu.wb.tools.DrawingTool; 

public class ShapeManager {	
	public function ShapeManager() {
		removeAll();
	}

    public function addShape(shapeID:String, dtool:DrawingTool):void {
        shapeMap.put(shapeID, dtool);        
    }

    public function createShape(shapeType:Number):DrawingTool {    	
    	var obj:DrawingTool = DrawingToolUtil.createDrawingTool(shapeType);
    	return obj;
    }
    
    public function createShape2(shapeType:Number):DrawingTool {    	
    	var obj:DrawingTool = DrawingToolUtil.createDrawingTool2(shapeType);
    	return obj;
    }

    public function getShape(shapeID:String):DrawingTool {        
        return shapeMap.getValue(shapeID) as DrawingTool;
    }

    public function removeShape(shapeID:String):void {
    	removeShapeFromStage(shapeID);
		shapeMap.remove(shapeID);		
    }

    public function removeAll():void {
        removeAllFromStage();        
        shapeMap.clear();        
    }

	// remove shape from stage
    private function removeShapeFromStage(shapeID:String):void {
    	var dtool:DrawingTool = getShape(shapeID);
    	whiteBoard.removeChild(dtool);		
    }

	// remove shapes from stage
    private function removeAllFromStage():void {
    	var keys:Array = shapeMap.getKeys();
    	
    	for(var i:int = 0; i < keys.length; i++) {
    		removeShapeFromStage(keys[i] as String);
    	}
    }
    
    public function setWhiteBoard(awhiteBoard:BlankPaperWrapper):void {
    	whiteBoard = awhiteBoard;
    }

    private var shapeMap:HashMap= new HashMap();// [shapeID, dtool]
    private var whiteBoard:BlankPaperWrapper;
}
}